//
//  XKBezierView.m
//  XKStudyDemo
//
//  Created by xukai on 2017/11/29.
//  Copyright © 2017年 xukai. All rights reserved.
//

#import "XKBezierView.h"

@implementation XKBezierView

-(void) drawRect:(CGRect)rect
{
    // 画路径
    UIBezierPath *path =[UIBezierPath bezierPath];
    [path moveToPoint:CGPointMake(10, 10)];
    [path addLineToPoint:CGPointMake(80, 58)];
    [path addLineToPoint:CGPointMake(30, 70)];
    [path addLineToPoint:CGPointMake(200, 90)];
    path.lineWidth = 3;
    
    // 反转路径
    UIBezierPath *reversingPath = [path bezierPathByReversingPath];
    reversingPath.lineWidth = 3;
    
    // 3. 为了避免两条路径混淆在一起, 我们为第一条路径做一个位移
    CGAffineTransform transform = CGAffineTransformMakeTranslation(200, 0);
    [path applyTransform: transform];
    

//    [path addLineToPoint: CGPointMake(self.frame.size.width*0.5, self.frame.size.height*0.5)];
//    [reversingPath addLineToPoint: CGPointMake(self.frame.size.width*0.5, self.frame.size.height*0.5)];

    [path addLineToPoint:CGPointMake(self.centerX, self.centerY)];
    [reversingPath addLineToPoint:CGPointMake(self.centerX, self.centerY)];

    
    
    //设置填充颜色和中风在当前绘图上下文
    [[UIColor redColor] set];
    [path stroke]; // 画
    
    [[UIColor greenColor] set];
    [reversingPath stroke]; // 画
}

@end
